<template>
	<Layout :class="'bg-white p-2'">
		<Row class="m-1 d-flex flex-row justify-content-between">
			<Button type="error" @click="newDistributor">新增</Button>
			<Input class="ml-3" v-model="searchObject.account" placeholder="输入账号"  />
			<Input class="ml-3" v-model="searchObject.name" placeholder="输入名称"  />
			<Input class="ml-3" v-model="searchObject.tel" placeholder="输入电话"  />
			<Button class="ml-3" type="primary" shape="circle" @click="search" icon="ios-search">查询</Button>
		</Row>

		<Layout :class="'bg-white'">
			<Table border :class="'m-1'" :columns="tableInfo.columnInfo" :data="tableInfo.data">
				<template slot-scope="{ row, index }" slot="img">
					<img style="width: 50px; height: 50px; border-radius: 25px;" :src="'https://'+row.img" />
				</template>
				<template slot-scope="{ row, index }" slot="statu">
					<span v-if="row.statu">开</span>
					<span v-else>关</span>
				</template>
				<template slot-scope="{ row, index }" slot="action">
					<!-- <Button type="primary" size="small" style="margin-right: 5px" @click="show(row.DistributorId)">详细</Button> -->
					<Button type="error" size="small" @click="remove(row.distributorId)">删除</Button>
				</template>
			</Table>
			<Page :class="'m-2 text-right'" :page-size="tableInfo.pageSize" @on-change="pageSearch" :total="tableInfo.total" />
		</Layout>
	</Layout>
</template>

<script>
	export default {
		data() {
			return {
					searchObject: {
						account: "",
						name: "",
						tel: "",
					},
					tableInfo: {
						currentPage: 1,
						total: 0,
						pageSize: 10,
						columnInfo: [
							{
								title: "编号",
								key: "distributorId",
								width: "70px",
							},
							{
								title: "封面图",
								slot: "img",
								width: "86px",
							},
							{
								title: "账户",
								key: "account",
								width: "136px",
							},
							{
								title: "名称",
								key: "name",
								width: "136px",
							},
							{
								title: "联系电话",
								key: "tel",
								width: "130px",
							},
							{
								title: "地址",
								key: "address",
							},
							{
								title: "状态",
								slot: "statu",
								width: "70px",
							},
							{
								title: "操作",
								slot: 'action',
								width: 150
							}
						],
						data: []
					}
				
			};
		},
		methods: {
			init: function() {
				this.tableInfo.currentPage = 0;
				this.search();
			},
			newDistributor: function() {
				this.$router.push({
					name: "distributor_new"
				});
			},
			show: function(distributorId) {
				this.$router.push({
					name: "distributor_detail",
					params: {
						distributorId
					}
				});
			},
			search: function() {
				this.http.get({
					url: "/distributor/info/page",
					param: {
						current: this.tableInfo.currentPage,
						account: this.searchObject.account,
						name: this.searchObject.name,
						tel: this.searchObject.tel,
					}
				}).then(data => {
					this.tableInfo.currentPage = data.current;
					this.tableInfo.total = data.total;
					this.tableInfo.pageSize = data.size;
					this.tableInfo.data = data.records;
				});
			},
			pageSearch: function(changedPage) {
				this.tableInfo.currentPage = changedPage;
				this.search();
			},
			remove: function(distributorId) {
				
				this.message.confirm({
					title: "删除提示",
					content: "即将删除经销商，确定吗？",
					onOk: () => {
						this.http.delete({
							url: "/distributor/info",
							param: {
								distributorId
							}
						}).then(data => {
							this.search();
						});
					},
					onCancel: () => {
						this.message.info('操作已取消');
					}
				});
			},
		},
		created: function() {
			this.init();
		},
	}
</script>

<style>
</style>
